import SwiftUI

/*
 * 日历示例
 */
class CalendarExample: FCUIView{
    /*
    * 触摸开始方法
    * view:视图
    * firstTouch:是否第一次触摸
    * firstPoint:第一次触摸的坐标
     * secondTouch:是否第二次触摸
    * secondPoint:第二次触摸的坐标
    */
    override func onTouchBegin(view:FCView, firstTouch:Bool, firstPoint:FCPoint, secondTouch:Bool, secondPoint:FCPoint) {
        super.onTouchBegin(view:view, firstTouch:firstTouch,  firstPoint:firstPoint, secondTouch:secondTouch, secondPoint:secondPoint)
    }

    /*
    * 触摸移动方法
    * view:视图
    * firstTouch:是否第一次触摸
    * firstPoint:第一次触摸的坐标
    * secondTouch:是否第二次触摸
    * secondPoint:第二次触摸的坐标
    */
    override func onTouchMove(view:FCView, firstTouch:Bool, firstPoint:FCPoint, secondTouch:Bool, secondPoint:FCPoint) {
        super.onTouchMove(view:view, firstTouch:firstTouch, firstPoint:firstPoint, secondTouch:secondTouch, secondPoint:secondPoint)
    }

    /*
    * 触摸结束方法
    * view:视图
    * firstTouch:是否第一次触摸
    * firstPoint:第一次触摸的坐标
    * secondTouch:是否第二次触摸
    * secondPoint:第二次触摸的坐标
    */
    override func onTouchEnd(view:FCView, firstTouch:Bool, firstPoint:FCPoint, secondTouch:Bool, secondPoint:FCPoint) {
        super.onTouchEnd(view:view, firstTouch:firstTouch, firstPoint:firstPoint, secondTouch:secondTouch, secondPoint:secondPoint)
    }

    /*
    * 点击方法
    * view:视图
    * firstTouch:是否第一次触摸
    * firstPoint:第一次触摸的坐标
    * secondTouch:是否第二次触摸
    * secondPoint:第二次触摸的坐标
    * clcks:点击次数
    */
    override func onClick(view:FCView, firstTouch:Bool, firstPoint:FCPoint, secondTouch:Bool, secondPoint:FCPoint, clicks:Int) {
        super.onClick(view:view, firstTouch:firstTouch, firstPoint:firstPoint, secondTouch:secondTouch, secondPoint:secondPoint, clicks: clicks)
    }

    /*
    * 重绘背景的实现方法
    * view:视图
    * paint:绘图对象
    * clipRect:裁剪区域
    */
    override func onPaint(view:FCView, paint:FCPaint, clipRect:FCRect) {
        super.onPaint(view:view, paint:paint, clipRect:clipRect)
    }

    /*
    * 重绘边框的实现方法
    * view:视图
    * paint:绘图对象
    * clipRect:裁剪区域
    */
    override func onPaintBorder(view:FCView, paint:FCPaint, clipRect:FCRect) {
        super.onPaintBorder(view:view, paint:paint, clipRect:clipRect)
    }
    
    /*
     * 初始化布局
     */
    override func onLoad(){
        let isInit = super.m_isInit
        super.onLoad()
        if !isInit{
            m_paint.defaultUIStyle = "light"
            let width = Double(self.frame.size.width), height = Double(self.frame.size.height)
            renderFaceCat(name:"calendarexample", paint: m_paint, size: FCSize(cx:width, cy:height))
            let tabPage = findViewByName(name:"TabPage2", views:m_paint.views)
            let calendar = FCCalendar()
            calendar.location = FCPoint(x:100, y:100)
            calendar.size = FCSize(cx:200, cy:300)
            addViewToParent(view: calendar, parent: tabPage)
            initCalendar(calendar:calendar)
            let cYear = getYear(years: &calendar.years, year:2022)
            if let cMonth = cYear.months[10]{
                if let cDay = cMonth.days[1]{
                    calendar.setSelectedDay(d: cDay)
                    updateCalendar(calendar:calendar)
                }
            }
        }
    }
}
